package com.wlyy.his.controller.registration;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wlyy.his.bean.register.vo.HisDeptVo;
import com.wlyy.his.service.registration.IHisDeptService;
import com.wlyy.his.entity.registration.HisDept;
import com.wlyy.his.common.api.CommonResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @deprecated 科室信息查询
 * @author 10097
 * @since 2021-09-01
 */
@RestController
@RequestMapping("/dept")
public class HisDeptController {

    @Resource
    public IHisDeptService hisDeptService;


    @GetMapping("all")
    public CommonResult<List<HisDeptVo>> findAll(@RequestParam String hisCode, @RequestParam(defaultValue = "0000001") String parentCode) {
        LambdaQueryWrapper<HisDept> queryWrapper = Wrappers.lambdaQuery(HisDept.class).eq(HisDept::getHisCode, hisCode).eq(HisDept::getParentCode, parentCode);
        List<HisDeptVo> hisDepts = hisDeptService.list(queryWrapper)
                .stream()
                //过滤为空的节点
                .filter(h -> !"".equals(h.getParentCode().trim()))
                //bean转换
                .map(h -> BeanUtil.toBean(h, HisDeptVo.class)).collect(Collectors.toList());
        //对结果进行转换，转换成树形结构
        return CommonResult.success(hisDepts);
    }

}

